/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cratos.xxgram.platf.message;

import org.redkale.service.RetResult;
import org.redkale.util.Comment;

import com.cratos.xxgram.platf.base.BaseEntity;

/**
 *
 * @author SquRab
 * @param <T>
 */
public class MessageResult<T> {

    protected int retcode;

    protected String retinfo;

    protected T result;

    protected short resultType;

    @Comment("消息发送结果")
    protected static final short MSG_SEND_RESULT_TYPE = 10;

    @Comment("单条消息")
    protected static final short MSG_RECORD_RESULT_TYPE = 20;

    @Comment("建立websocket 连接")
    protected static final short WSLOGIN_RESULT_TYPE = 40;

    @Comment("账号重复登录")
    protected static final short RETEAPLOGIN_RESULT_TYPE = 50;

    @Comment("服务器重启  掉线")
    protected static final short OFFLINE_RESULT_TYPE = 60;

    @Comment("消息发送超时")
    protected static final short REQ_TIME_OUT = 70;

    public static <T> MessageResult<T> build(T result, short type) {
        MessageResult messageResponse = new MessageResult();
        messageResponse.setResult(result);
        messageResponse.setResultType(type);
        return messageResponse;
    }

    @Comment("登录结果发送")
    public static MessageResult<LoginResult> buildLogin(LoginResult result) {
        return build(result, WSLOGIN_RESULT_TYPE);
    }

    @Comment("消息发送结果")
    public static MessageResult<SendMsgResponse> buildSendResult(SendMsgResponse result) {
        return build(result, MSG_SEND_RESULT_TYPE);
    }

    @Comment("普通消息发送")
    public static MessageResult<MessageRecord> buildRecord(MessageRecord result) {
        return build(result, MSG_RECORD_RESULT_TYPE);
    }

    @Comment("账号重复登录")
    public static MessageResult<RepeatedLoginResult> buildRepeatedLogin(RepeatedLoginResult result) {
        return build(result, RETEAPLOGIN_RESULT_TYPE);
    }

    @Comment("账号重复登录")
    public static MessageResult<OffLineResult> buildOffLine(OffLineResult result) {
        return build(result, OFFLINE_RESULT_TYPE);
    }

    @Comment("请求超时")
    public static MessageResult<ReqTimeOutResult> buildReqTimeOut(ReqTimeOutResult result) {
        return build(result, REQ_TIME_OUT);
    }

    public static <T> MessageResult<T> error(RetResult result) {
        MessageResult messageResponse = new MessageResult();
        messageResponse.setRetcode(result.getRetcode());
        messageResponse.setRetinfo(result.getRetinfo());
        return messageResponse;
    }

    public int getRetcode() {
        return retcode;
    }

    public void setRetcode(int retcode) {
        this.retcode = retcode;
    }

    public String getRetinfo() {
        return retinfo;
    }

    public void setRetinfo(String retinfo) {
        this.retinfo = retinfo;
    }

    public T getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }

    public short getResultType() {
        return resultType;
    }

    public void setResultType(short resultType) {
        this.resultType = resultType;
    }

    @Comment("消息发送结果")
    public static final class SendMsgResponse extends BaseEntity {

        private String messageid;

        private int targetid;

        private int msgtype;

        private int msgkind;

        @Comment("消息创建时间")
        private long createtime;

        public SendMsgResponse() {
            // TODO Auto-generated constructor stub
        }

        public SendMsgResponse(String messageid, int targetid, int msgtype, int msgkind, long createtime) {
            super();
            this.messageid = messageid;
            this.targetid = targetid;
            this.msgtype = msgtype;
            this.msgkind = msgkind;
            this.createtime = createtime;
        }

        public String getMessageid() {
            return messageid;
        }

        public void setMessageid(String messageid) {
            this.messageid = messageid;
        }

        public int getTargetid() {
            return targetid;
        }

        public void setTargetid(int targetid) {
            this.targetid = targetid;
        }

        public int getMsgtype() {
            return msgtype;
        }

        public void setMsgtype(int msgtype) {
            this.msgtype = msgtype;
        }

        public int getMsgkind() {
            return msgkind;
        }

        public void setMsgkind(int msgkind) {
            this.msgkind = msgkind;
        }

        public long getCreatetime() {
            return createtime;
        }

        public void setCreatetime(long createtime) {
            this.createtime = createtime;
        }

    }

    @Comment("登录结果")
    public static final class LoginResult {

        private String jsessionid;

        public String getJsessionid() {
            return jsessionid;
        }

        public void setJsessionid(String jsessionid) {
            this.jsessionid = jsessionid;
        }

    }

    @Comment("账号重复登录")
    public static final class RepeatedLoginResult {

        private String desc = "";

        public RepeatedLoginResult() {

        }

        public RepeatedLoginResult(String desc) {
            this.desc = desc;
        }

        public String getDesc() {
            return desc;
        }

        public void setDesc(String desc) {
            this.desc = desc;
        }

    }

    @Comment("掉线通知")
    public static final class OffLineResult {

        private String desc = "";

        public OffLineResult() {
        }

        public OffLineResult(String desc) {
            this.desc = desc;
        }

        public String getDesc() {
            return desc;
        }

        public void setDesc(String desc) {
            this.desc = desc;
        }

    }

    @Comment("请求超时结果")
    public static final class ReqTimeOutResult {

        private String desc = "";

        public ReqTimeOutResult() {
        }

        public ReqTimeOutResult(String desc) {
            this.desc = desc;
        }

        public String getDesc() {
            return desc;
        }

        public void setDesc(String desc) {
            this.desc = desc;
        }
    }
}
